package com.zx.tradeclient.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zx.tradeclient.R;
import com.zx.tradeclient.entity.CategoryInfo;

public class CategoryAdapter extends BaseAdapter {

	private ArrayList<CategoryInfo> list = new ArrayList<CategoryInfo>();
	private LayoutInflater inflater;
	private ViewHolder holder = null;
	
	public CategoryAdapter(Context context, ArrayList<CategoryInfo> img) {
		list = img;
		this.inflater=LayoutInflater.from(context);
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (convertView == null) {
			convertView=inflater.inflate(R.layout.category_item, null);
			holder=new ViewHolder();
			holder.cate_text=(TextView)convertView.findViewById(R.id.category_item_text);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder)convertView.getTag();
		}
		
		
		CategoryInfo info=list.get(position);
		holder.cate_text.setText(info.getCategory_name());
		
		
		return convertView;
	}
	
	static class ViewHolder{
		
		public TextView cate_text;
		
	}

}